package example.cloudsitemanagement8001.util;

import lombok.Data;

@Data
public class CommonResult<T> {
    private long code;
    private String message;
    private T data;
    public CommonResult() {}
    public CommonResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<>(200, "操作成功", data);
    }
    public static <T> CommonResult<T> successMessage(String message) {
        return new CommonResult<>(200, message, null);
    }
    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<>(500, message, null);
    }

    /**
     * 返回失败结果
     * @param message 提示信息
     * @param data 数据
     */
    public static <T> CommonResult<T> failed(String message, T data) {
        return new CommonResult<>(500, message, data);
    }
}
